package org.shoukaiseki.commons.utils;

import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.text.StrBuilder;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  18-10-23 下午5:53<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
public class NameUtils {

    static Pattern humpPattern = Pattern.compile("[_-](\\w)");

    /**
     * 将 -_ 转换为驼峰命名
     * @param name
     * @return
     */
    public static String humpName(String name){
        String humpName=name.toLowerCase();
        Matcher matcher = humpPattern.matcher(humpName);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            // 获取正则表达式中的第一个 () 中的组
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

    /**
     * 首字符 小写
     * @param name
     * @return
     */
    public static String firstLetterLowerCase(String name)
    {
        int strLen;
        if (name == null || (strLen = name.length()) == 0)
        {
            return name;
        }
        return new StringBuffer(strLen).append(Character.toLowerCase(name.charAt(0))).append(name.substring(1)).toString();
    }

    /**
     * 首字母 大写
     * @param name
     * @return
     */
    public static String firstLetterUppercase(String name){
        int strLen;
        if (name == null || (strLen = name.length()) == 0)
        {
            return name;
        }
        return new StringBuffer(strLen).append(Character.toUpperCase(name.charAt(0))).append(name.substring(1)).toString();
    }


}
